package com.dykj.fireFighting.web;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.office.OfficeManager;
import org.jodconverter.local.LocalConverter;
import org.jodconverter.local.office.LocalOfficeManager;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,})
@EnableAspectJAutoProxy
@EnableDiscoveryClient
@EnableDubbo
@MapperScan(value = "com.dykj.fireFighting.web.mapper")
@EnableMongoRepositories
public class FireFightingWebFileApplication {

    /**
     * libreOffice安装位置
     */
    @Value("${libreOffice.win}")
    private String win;

    /**
     * libreOffice安装位置
     */
    @Value("${libreOffice.linux}")
    private String linux;


    public static void main(String[] args) {
        SpringApplication.run(FireFightingWebFileApplication.class, args);
    }

    @Bean(
            initMethod = "start",
            destroyMethod = "stop"
    )
    public OfficeManager officeManager() {
        String os = System.getProperty("os.name").toLowerCase();
        return LocalOfficeManager.builder()
                .officeHome(os.contains("windows") ? win : linux)
                .portNumbers(8100, 8102, 8103)
                .maxTasksPerProcess(100)
                .build();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnBean({OfficeManager.class})
    public DocumentConverter jodConverter(OfficeManager officeManager) {
        return LocalConverter.make(officeManager);
        //return null;
    }


}
